package com.javatest.springbootactivemq.produce;

import java.util.UUID;
import javax.jms.Topic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA. Description:
 *
 * @author lzy
 * @create 2019-12-03 上午9:45
 */
@Slf4j
@Component
public class TopicProducer {

  @Autowired private JmsMessagingTemplate messagingTemplate;

  @Autowired private Topic topic;

  @Scheduled(fixedDelay = 3000)
  public void produceTopic() {
    messagingTemplate.convertAndSend(
        topic, "*****主题消息:" + UUID.randomUUID().toString().substring(0, 6));
    log.info("publish topic message");
  }
}
